/**
 * 
 */
package com.jeesuite.bestpl.rest.controller;

import javax.inject.Singleton;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jeesuite.bestpl.api.IUserService;
import com.jeesuite.bestpl.dto.User;
import com.jeesuite.bestpl.dto.request.LoginRequest;
import com.jeesuite.bestpl.dto.request.RegisterRequest;

/**
 * @description <br>
 * @author <a href="mailto:vakinge@gmail.com">vakin</a>
 * @date 2016年10月25日
 */
@Component
@Singleton
@Path("/user")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED})
public class UserController {
	
	@Autowired
	private IUserService userService;
	
	@POST
	@Path("register")
	public User registerUser(RegisterRequest request){
		return userService.register(request);
	}
	
	@POST
	@Path("login")
	public User login(LoginRequest request){
		User user = userService.login(request.getLoginName(), request.getPasswaord());
		return user;
	}
	
	@GET
	@Path("{id}")
	public User getUser(@PathParam("id") int userId){
		return userService.getUser(userId);
	}
	
	

}
